require 'View/UIBase/UIBase'

UIMonthCardConfirmTips = UIBase.New(PanelResNames.UIMonthCardConfirmTips)

function UIMonthCardConfirmTips.Init(func, id, subId)
    UIMonthCardConfirmTips.activeId = id;
    UIMonthCardConfirmTips.subId = subId;
    UIBase.Init(UIMonthCardConfirmTips, func);
end

function UIMonthCardConfirmTips:OnCreate()
    self.tipsTitle = self:GetChild("title")
    self.tipsTips = self:GetChild("tips")
    self.tipstitleTips = self:GetChild("titleTips")
    self.tipstitleTips.text = getLanguage("MonthlyCardTips01")
    self.tipsBuy = self:GetChild("buy")
    self.tipsBuy.title = getLanguage("OptionalPool_Btn_Buy")
    self.tipsCancel = self:GetChild("cancel")
    self.tipsCancel.title = getLanguage("Btn_Cancel")
    self.tipsNum = self:GetChild("num")
    self.tipsIcon = self:GetChild("icon")

    self:RegisterOnClick(self.tipsCancel,self.OnClose);
    self:RegisterOnClick(self.tipsBuy,self.OnBuy);
end

-- 显示
function UIMonthCardConfirmTips:OnEnable()
    if self.activeId == nil or self.subId == nil then
        self:OnBack();
    else
        self:Refresh();
    end
end

function UIMonthCardConfirmTips:Refresh()
    self.severData, self.monthCardData, self.monthTableName = logicMgr.CostManager.getCostData(self.activeId);
    self:ShowTips(self.subId);
end

function UIMonthCardConfirmTips:ShowTips(key)
    local tableData = self.monthCardData[tostring(key)];
    if tableData == nil then
        return ;
    end
    self.cheekItemId = key;
    self.cheekItemMoney = tableData.f_Price;
    self.cheekItemProductId = tableData.f_ProductId;
    local data = decodeJsonStrToTabel(tableData.f_TradeReward);
    self.tipsTitle.text = getLanguage(tableData.f_MonthlyCardName);
    self.tipsNum.text = "+"..data[1][2];
    self.tipsTips.text = getLanguage(tableData.f_MassageInfo);
    local itemData = logicMgr.ItemManager.getItemConstDatabyModelId(data[1][1]);
    if itemData ~= nil then
        self.tipsIcon.url = EnumConst.AtlasPath.ItemAtlas..itemData.icon;
    end
end

function UIMonthCardConfirmTips:OnBuy()
    logicMgr.CostManager.getRewardByIdAndIndex(self.activeId, self.cheekItemId, self.cheekItemProductId, 1, self.cheekItemMoney, self.onBuySuccess, self);
    self:OnClose();
end

function UIMonthCardConfirmTips:onBuySuccess(id, index)
end

-- 关闭
function UIMonthCardConfirmTips:OnClose()
    self:OnBack();
end

-- 隐藏
function UIMonthCardConfirmTips:OnDisable()
end

-- 卸载
function UIMonthCardConfirmTips:OnDestroy()
end

return UIMonthCardConfirmTips